﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Catering.Catering_Page.system
{
    public partial class MainDeputyAuto : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.LoadData();
            }
        }

        //加载页面数据
        public void LoadData()
        {
            DataTable dt_RawMaterialsType = new Catering_Rules.RawMaterialsType().GetAllList().Tables[0];
            this.Drop_RawMaterialsType.LoadDrop(dt_RawMaterialsType, "id", "Name");

            this.LoadRep();
        }

        //加载数据列表
        public void LoadRep()
        {
            DataTable dt_MainDeputyAuto = new Catering_Rules.MainDeputyAuto().GetList("1=1 order by MainDID").Tables[0];
            this.Rep_AutoRecipe.DataSource = dt_MainDeputyAuto;
            this.Rep_AutoRecipe.DataBind();
        }

        protected void Rep_AutoRecipe_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.MainDeputyAuto().Delete(delID))
                {
                    this.LoadRep();
                }
            }
        }

        protected void btn_Add_Click(object sender, EventArgs e)
        {
            Catering_Model.MainDeputyAuto md = new Catering_Model.MainDeputyAuto();
            md.id = new Catering_Rules.MainDeputyAuto().GetMaxId();
            md.MainDID = Convert.ToInt32(this.Drop_MinD.SelectedValue);
            md.RawMaterialsTypeID = Convert.ToInt32(this.Drop_RawMaterialsType.SelectedValue);
            new Catering_Rules.MainDeputyAuto().Add(md);
            this.LoadRep();
        }
    }
}